DAY42:Consecutive strings


Posted by birdbirdmurmur on 2023-08-24

題目連結

https://www.codewars.com/kata/56a5d994ac971f1ac500003e

解法

function longestConsec(strarr, k) {
    if (k <= 0 || strarr.length === 0) {
        return '';
    }

    let long = ''
    for (let i = 0; i < strarr.length - k + 1; i++) {
        const currString = strarr.slice(i, i + k).join('')
        if (currString.length > long.length) {
            long = currString
        }
    }
    return long
}

筆記


#javascript #Codewars







Related Posts

Command line:command line interface 介紹及基本指令

Command line:command line interface 介紹及基本指令

有空的話來學一下 Tailwind CSS - Week 3

有空的話來學一下 Tailwind CSS - Week 3

[Note] Node.js + express + EJS

[Note] Node.js + express + EJS


Comments